﻿using ComputedTable.Version10;
using MortgageCalculator.Demo;
using System;
using System.Collections.Generic;

namespace MortgageCalculator.Tests
{
    public class FakeCalculator : ICalculator<MortgageCalculatorOperationContext>
    {
        public CellOperationResult ExecuteResult { get; set; }
        public string Name { get; set; }
        public List<CellOperationResult> ExecuteResults { get; set; }
        public int ExecuteCount { get; set; }
        public Func<MortgageCalculatorOperationContext, CellOperationResult> ExecuteDelegate { get; set; }

        public CellOperationResult Execute(MortgageCalculatorOperationContext context)
        {
            this.ExecuteCount++;

            if (this.ExecuteDelegate != null)
            {
                return this.ExecuteDelegate(context);
            }

            if (this.ExecuteResults != null)
            {
                return this.ExecuteResults[this.ExecuteCount - 1];
            }

            if (this.ExecuteResult != null)
            {
                return this.ExecuteResult;
            }

            throw new InvalidOperationException("ExecuteResult is undefined.");
        }
    }
}
